/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
 package com.wealth.merchant.entity;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.context.annotation.Lazy;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wealth.system.entity.User;

@Entity
@Table(name = "t_merchant_merchant")
public class Merchant implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Long id;
	private String name;
	private String linkman;
	private String telephone;
	private String address;
	private String intro;
	private String picurl;
	private String chiefDishes;
	private Double longitude;
	private Double latitude;
	private Integer seq;
	
	private Double scale;
	private String cardno;
	private String cardholder;
	private String bank;
	private Integer status;
	private String creator;
	private Date createTime;
	private Integer isPicked;
	

	private BusinessDistrict district;
	private Market market;
	private List<User> userList = new ArrayList<User>();
	private List<MerchantPic> merchantPicList = new ArrayList<MerchantPic>();
	private Integer type;//类型，1 = 限时抢购 2=天天特价 3=超值折扣
	private Date startTime;//开始时间
	private Date endTime;//结束时间
	
	/* ---------------- method ----------------*/
	
	public Merchant(){
	}

	public Merchant(Long id){
		this.id = id;
	}

	/* ---------------- getter/setter ----------------*/
	
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "name")
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name = "linkman")
	public String getLinkman() {
		return linkman;
	}
	
	public void setLinkman(String linkman) {
		this.linkman = linkman;
	}
	
	@Column(name = "telephone")
	public String getTelephone() {
		return telephone;
	}
	
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	
	@Column(name="isPicked")
	public Integer getIsPicked() {
		return isPicked;
	}

	public void setIsPicked(Integer isPicked) {
		this.isPicked = isPicked;
	}

	@Column(name = "address")
	public String getAddress() {
		return address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	@Column(name = "intro")
	public String getIntro() {
		return intro;
	}
	
	public void setIntro(String intro) {
		this.intro = intro;
	}
	
	@Column(name = "picurl")
	public String getPicurl() {
		return picurl;
	}
	
	public void setPicurl(String picurl) {
		this.picurl = picurl;
	}
	
	@Column(name = "chief_dishes")
	public String getChiefDishes() {
		return chiefDishes;
	}
	
	public void setChiefDishes(String chiefDishes) {
		this.chiefDishes = chiefDishes;
	}
	
	@Column(name = "longitude")
	public Double getLongitude() {
		return longitude;
	}
	
	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	@Column(name = "latitude")
	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	@Column(name = "seq")
	public Integer getSeq() {
		return seq;
	}
	
	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@Column(name = "scale")
	public Double getScale() {
		return scale;
	}
	
	public void setScale(Double scale) {
		this.scale = scale;
	}
	
	@Column(name = "cardno")
	public String getCardno() {
		return cardno;
	}
	
	public void setCardno(String cardno) {
		this.cardno = cardno;
	}
	
	@Column(name = "cardholder")
	public String getCardholder() {
		return cardholder;
	}
	
	public void setCardholder(String cardholder) {
		this.cardholder = cardholder;
	}
	
	@Column(name = "bank")
	public String getBank() {
		return bank;
	}
	
	public void setBank(String bank) {
		this.bank = bank;
	}
	
	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@Column(name = "creator")
	public String getCreator() {
		return creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@ManyToOne
	@JoinColumn(name="district_id")
	public BusinessDistrict getDistrict() {
		return district;
	}

	public void setDistrict(BusinessDistrict district) {
		this.district = district;
	}
	
	@ManyToOne
	@JoinColumn(name="market_id") 
	public Market getMarket() {
		return market;
	}

	public void setMarket(Market market) {
		this.market = market;
	}

	@ManyToMany
	@JoinTable(name = "t_merchant_user", 
		joinColumns = { @JoinColumn(name = "merchant_id") },
		inverseJoinColumns = { @JoinColumn(name = "user_id") }
	)
	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
	
	@JsonIgnore
	@OneToMany(mappedBy = "merchant")
	public List<MerchantPic> getMerchantPicList() {
		return merchantPicList;
	}

	public void setMerchantPicList(List<MerchantPic> merchantPicList) {
		this.merchantPicList = merchantPicList;
	}

	@Transient
	public String getUsername(){
		List<User> userList = getUserList();
		if(userList.size()>0){
			return userList.get(0).getUsername();
		}else{
			return "";
		}
	}

	@Column(name = "type")
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Column(name = "startTime")
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@Column(name = "endTime")
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	
}



